<?php

/**
 * 管理员登录验证
*/  
    //开启Session 
    session_start();
    include '../iframe/public/db_object.php';

    if(isset($_POST)){
        $login_name = trim($_POST['login_name']);
        $login_pwd = trim($_POST['login_pwd']);

        $db = new DB_object(["db_name"=> "db_shop"]);

        $sql_name = "select * from sys_user where login_name="."'$login_name'";
        $l_data = $db->l_select_one($sql_name);
        if(empty($l_data)){
            echo 0; // 用户名不存在
            exit;
        }
        
        $salt = $l_data['ssalt'];
        $l_pwd = md5($login_pwd.$salt);
    
        if($l_pwd == $l_data['login_pwd']){
            // 存储session
            $_SESSION['login_name'] = $login_name;
            echo 1; // 登录成功
        }else{
            echo 2; // 密码错误
        }

    }   
?>